const VueLoaderPlugin = require('vue-loader/lib/plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')

module.exports = {
  mode: 'none',
  entry: './src/main.js',
  // baseurl: './',
  output: {
    filename: 'bundle.js',
    path: __dirname + '/dist'
    // publicPath: '/'
  },
  devServer: {
    hot: true,
    contentBase: ['./public']
  },
  optimization: {
    splitChunks: {
      // 自动提取所有公共模块到单独 bundle
      chunks: 'all'
    }
  },
  module: {
    rules: [
      {
        test: /\.(js｜vue)$/,
        exclude: /node_modules/,
        use: 'eslint-loader',
        enforce: 'pre'
        //     use: {
        //         loader: 'babel-loader',
        //         options: {
        //             presets: ['@babel/preset-env']
        //         }
        //     }
      },
      {
        test: /\.vue$/,
        use: 'vue-loader'
      },
      {
        test: /\.less$/,
        use: [
          // 'vue-style-loader',
          // 'style-loader',
          MiniCssExtractPlugin.loader,
          'css-loader',
          'less-loader'
        ]
      },
      {
        test: /\.png$/,
        use: {
          loader: 'url-loader',
          options: {
            limit: 2 * 1024,
            esModule: false
          }
        }
      },
      {
        test: /\.html$/,
        use: {
          loader: 'html-loader',
          options: {
            attributes: {
              list: [
                // '...',  // 使用所有默认支持的标签和属性
                {
                  tag: 'img',
                  attribute: 'data-src',
                  type: 'src'
                },
                {
                  tag: 'a', // 标签名
                  attribute: 'href', // 属性名
                  type: 'src' // 解析类型，src 或 srcset
                }
              ]
            }
          }
        }
      }
    ]
  },
  plugins: [
    new VueLoaderPlugin(),
    new HtmlWebpackPlugin({
      title: 'webpack html plugin sample',
      meta: {
        viewport: 'width=device-width'
      },
      template: './public/index.html'
    }),
    new MiniCssExtractPlugin()
  ]
}
